﻿// -----------------------------------------------------------------------
// <copyright file="CampfireClient.cs" company="Spardo, LLC">
// Copyright (c) 2011 SPardo, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the 
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
// </copyright>
// -----------------------------------------------------------------------

namespace DotNet37Signals.Client.Campfire
{
    using System;
    using DotNet37Signals.Client.Campfire.Contracts;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class CampfireClient : IDisposable
    {
        internal Credentials Credentials { get; private set; }

        public CampfireClient(Credentials credentials)
        {
            this.Credentials = credentials;
        }

        public T GetContract<T>() where T : class, ICampfireContract
        {
            return new RestClientBase<T>(this.Credentials, "campfirenow.com", true).GetContract();
        }

        #region IDisposable Members

        public void Dispose()
        {
            this._account = null;
            this._messages = null;
            this._rooms = null;
            this._search = null;
            this._transcripts = null;
            this._users = null;
        }

        #endregion

        private IAccountContract _account;
        public IAccountContract Account
        {
            get { return this._account ?? (this._account = this.GetContract<IAccountContract>()); }
        }

        private IMessagesContract _messages;
        public IMessagesContract Messages
        {
            get { return this._messages ?? (this._messages = this.GetContract<IMessagesContract>()); }
        }

        private IRoomsContract _rooms;
        public IRoomsContract Rooms
        {
            get { return this._rooms ?? (this._rooms = this.GetContract<IRoomsContract>()); }
        }

        private ISearchContract _search;
        public ISearchContract Search
        {
            get { return this._search ?? (this._search = this.GetContract<ISearchContract>()); }
        }

        private ITranscriptsContract _transcripts;
        public ITranscriptsContract Transcripts
        {
            get { return this._transcripts ?? (this._transcripts = this.GetContract<ITranscriptsContract>()); }
        }

        private IUsersContract _users;
        public IUsersContract Users
        {
            get { return this._users ?? (this._users = this.GetContract<IUsersContract>()); }
        }
    }
}
